class Solution
{
public:
    bool checkPalindromeFormation(string a, string b)
    {
        int n = a.size();
        int aPre_bSuf = 0;
        int bPre_aSuf = 0;
        while (aPre_bSuf < n / 2)
        {
            if (a[aPre_bSuf] == b[n - aPre_bSuf - 1])
            {
                ++aPre_bSuf;
            }
            else
            {
                break;
            }
        }
        int innerA = aPre_bSuf;
        int innerB = aPre_bSuf;
        while (innerA < n / 2)
        {
            if (a[innerA] == a[n - innerA - 1])
            {
                ++innerA;
            }
            else
            {
                break;
            }
        }
        if (innerA >= n / 2)
        {
            return true;
        }
        while (innerB < n / 2)
        {
            if (b[innerB] == b[n - innerB - 1])
            {
                ++innerB;
            }
            else
            {
                break;
            }
        }
        if (innerB >= n / 2)
        {
            return true;
        }
        while (bPre_aSuf < n / 2)
        {
            if (b[bPre_aSuf] == a[n - bPre_aSuf - 1])
            {
                ++bPre_aSuf;
            }
            else
            {
                break;
            }
        }
        while (bPre_aSuf < n / 2)
        {
            if (a[bPre_aSuf] == a[n - bPre_aSuf - 1])
            {
                ++bPre_aSuf;
            }
            else
            {
                break;
            }
        }
        innerA = bPre_aSuf;
        innerB = bPre_aSuf;
        while (innerA < n / 2)
        {
            if (a[innerA] == a[n - innerA - 1])
            {
                ++innerA;
            }
            else
            {
                break;
            }
        }
        if (innerA >= n / 2)
        {
            return true;
        }
        while (innerB < n / 2)
        {
            if (b[innerB] == b[n - innerB - 1])
            {
                ++innerB;
            }
            else
            {
                break;
            }
        }
        if (innerB >= n / 2)
        {
            return true;
        }
        return false;
    }
};